import fetcher from "../apis/Fetcher";
import {Page, Pageable} from "../utils/Page";
import {NumberIdAndName} from "../types/BasicModels";

export interface QueryGoodsBrandsRequest {
    name?: string
}

export function queryGoodsBrands(queryGoodsBrandsRequest: QueryGoodsBrandsRequest, pageable: Pageable) {
    return fetcher.get<Page<QueryGoodsBrandsResponse>>("/goodsBrands", {...queryGoodsBrandsRequest, ...pageable.toRequestParams()})
}

export interface QueryGoodsBrandsResponse{
    id:number
    name:string
    goodsAmount:number
    factory?:NumberIdAndName

    group?:NumberIdAndName
}

export interface CreateGoodsBrandRequest{
    name:string
    factoryId?:number
    groupId?:number
}

export function createGoodsBrand(createGoodsBrandRequest:CreateGoodsBrandRequest){
    return fetcher.post("goodsBrands",{},createGoodsBrandRequest)
}

export function updateGoodsBrand(id:number,createGoodsBrandRequest:CreateGoodsBrandRequest){
    return fetcher.put(`goodsBrands/${id}`,{},createGoodsBrandRequest)
}

export function getAllGoodsBrand(){
    return fetcher.get<Array<GoodsBrandSummary>>("goodsBrands")
}

export interface GoodsBrandSummary{
    id:number
    name:string
    group?:NumberIdAndName
}

export function deleteGoodsBrand(id:number){
    return fetcher.delete(`goodsBrands/${id}`)
}